package com.incar.chuxing.utils;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

import com.incar.chuxing.R;

public class EditTextMonitorUtils implements TextWatcher {

    private TextView tv_button;
    private EditText[] text;
    private boolean flag;
    public boolean clickflag;

    public void SetMonitorEditText(final TextView tv_button, final boolean flag, final EditText... text) {

        this.tv_button = tv_button;
        this.text = text;
        this.flag = flag;

        for (int i = 0; i < text.length; i++) {

            if (text[i] != null) {

                text[i].addTextChangedListener(EditTextMonitorUtils.this);
            }

        }
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
                                  int after) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub
        for (int i = 0; i < text.length; i++) {

            if (text[i].length() != 0 && flag == true) {

                tv_button.setBackgroundResource(R.drawable.btn_bg);
                tv_button.setEnabled(true);
            } else {

                tv_button.setBackgroundResource(R.drawable.btn_gray_bg);
                tv_button.setEnabled(false);
                return;
            }
        }
    }

}
